home *** CD-ROM | disk | FTP | other *** search
/ Young Minds / Young Minds Interactive CD-ROM.ISO / crystal / cvmove.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-01-12  |  3.4 KB  |  148 lines

  1. /* cvmove.c
  2.  *   various object motion subroutines
  3.  *************************************************************************/
  4.  
  5. #include <stdio.h>
  6. #include "cvobj.h"
  7. #include "cvlocs.h"
  8.  
  9. extern void bug() ;
  10. extern int holding ;
  11.  
  12. /* start toting an object, removing it from the list of things at its
  13.  * former location.  Increment 'holding' unless it was already being
  14.  * toted.
  15.  * Primarily used by move().
  16.  */
  17. void
  18. carry(obj) register struct cvobj *obj;
  19. {    register struct cvloc *from;
  20.     register struct conn *this;
  21.  
  22.     from = obj->conn1.where ;
  23.     obj->conn1.where = TAKEN ;
  24.     if (from == TAKEN) return ;
  25.     ++holding ;
  26.     if (from != (struct cvloc *) NULL)
  27.     {    for ( this = &(from->atloc);
  28.             this->link != &(obj->conn1); this = this->link)
  29.             if (this->link == NULL) bug(30);
  30.         this->link = obj->conn1.link ;
  31.     }
  32.     obj->conn1.link = NULL ;
  33.     return;
  34. }
  35.  
  36. /* pick up an object by its second location, removing it from the list
  37.  * of things at its former location.
  38.  * Primarily used by move2().
  39.  */
  40. static void
  41. carry2(obj) register struct cvobj *obj;
  42. {    register struct cvloc *from;
  43.     register struct conn *this;
  44.  
  45.     from = obj->conn2.where ;
  46.     obj->conn2.where = TAKEN ;
  47.     if (from == TAKEN) return ;
  48.     if (from != (struct cvloc *) NULL)
  49.     {    for ( this = &(from->atloc);
  50.             this->link != &(obj->conn2); this = this->link)
  51.             if (this->link == NULL) bug(30);
  52.         this->link = obj->conn2.link ;
  53.     }
  54.     obj->conn2.link = NULL ;
  55.     return;
  56. }
  57.  
  58. /* place any object anywhere by picking it up and dropping it.
  59.  * may already be toting it, in which case the carry is a no-op.
  60.  *
  61.  * to move the second place of an object, use the object's number plus
  62.  * OBJSIZ as the object.
  63.  *
  64.  * 'move' may be called regardless of where the object was, whether
  65.  * it's being carried, is lost, is destroyed, or whatever.
  66.  */
  67. void
  68. move(obj,toloc)
  69.     register struct cvobj *obj;
  70.     register struct cvloc *toloc;
  71. {
  72.     register struct cvloc *from;
  73.  
  74.     from = obj->conn1.where ;
  75.     if ((from != LOST) && (from != TAKEN)) carry(obj);
  76.  
  77.     if (obj->conn1.where == TAKEN) --holding ;
  78.     obj->conn1.where = toloc ;
  79.     if (toloc == LOST) return ;
  80.     obj->conn1.link = toloc->atloc.link ;
  81.     toloc->atloc.link = &(obj->conn1) ;
  82.     return;
  83. }
  84.  
  85. /* place any object anywhere by picking it up and dropping it by its
  86.  * second location.  May already be toting it, in which case the carry
  87.  * is a no-op.
  88.  *
  89.  * 'move2' may be called regardless of where the object was, whether
  90.  * it's being carried, is lost, is destroyed, or whatever.
  91.  */
  92. void
  93. move2(obj,toloc)
  94.     register struct cvobj *obj;
  95.     register struct cvloc *toloc;
  96. {
  97.     register struct cvloc *from;
  98.  
  99.     from = obj->conn2.where ;
  100.     if ((from != LOST) && (from != TAKEN)) carry2(obj);
  101.  
  102.     if (obj->conn2.where == TAKEN) --holding ;
  103.     obj->conn2.where = toloc ;
  104.     if (toloc == LOST) return ;
  105.     obj->conn2.link = toloc->atloc.link ;
  106.     toloc->atloc.link = &(obj->conn2) ;
  107.     return;
  108. }
  109.  
  110.  
  111. /* juggle an object by picking it up and putting it down again, the
  112.  * purpose being to get the object to the front of the chain of things
  113.  * at its location.
  114.  */
  115. void
  116. juggle(obj) register struct cvobj *obj;
  117. {
  118.     register struct cvloc *where;
  119.  
  120.     where = obj->conn1.where ;
  121.     if (where == NULL) bug(33);
  122.     move(obj,where);
  123.     return;
  124. }
  125.  
  126. void
  127. juggl2(obj) register struct cvobj *obj;
  128. {    register struct cvloc *where;
  129.  
  130.     where = obj->conn2.where ;
  131.     if (where == NULL) bug(33);
  132.     move2(obj,where);
  133.     return;
  134. }
  135.  
  136.  
  137. /* destroy the object by dropping at an inaccessable place
  138.  */
  139. void
  140. destry(obj) register struct cvobj *obj;
  141. {    move(obj,LOST);
  142. }
  143.  
  144. void
  145. destr2(obj) register struct cvobj *obj ;
  146. {    move2(obj,LOST);
  147. }
  148.